package demo.spring.framework.scheduling.annotation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 调度任务
 * 
 * @author junying.han
 *
 */
@Component("scheduledTaskDemo")
public class ScheduledTaskDemo {

    static Logger logger = LoggerFactory.getLogger(ScheduledTaskDemo.class);

    @Scheduled(cron = "0/3 * * * * ?")
    public void job1() {
        logger.info("@Scheduled 注解的job");
    }

    /**
     * 私有方法也可以识别哦
     */
    @Scheduled(cron = "0/3 * * * * ?")
    private void job2() {
        logger.info("@Scheduled 注解的job2");
    }

    public void jobByXmlCfg() {
        logger.info("XML 配置的job");
    }

    public static void main(String[] args) {
        String[] paths = { "/spring/ctx-task.xml" };
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(paths);
        ctx.start();
    }
}
